'''
* This is the projet for Brtc LlmOps Platform
* @Author Leon-liao <liaosiliang@alltman.com>
* @Description //TODO 
* @File: oauth.py
* @Time: 2025/10/11
* @All Rights Reserve By Brtc
'''
from abc import ABC, abstractmethod
from dataclasses import dataclass


@dataclass
class OAuthUserInfo:
    """OAuth用户基础信息,只记录id/name/email"""
    id:str
    name:str
    email:str

@dataclass
class OAuth(ABC):
    """第三方授权登录认证基础类"""
    client_id:str #客户端id
    client_secret:str#客户端密钥
    redirect_uri:str#重定向url


    @abstractmethod
    def get_provider(self)->str:
        """获取服务商的名字"""
        pass


    @abstractmethod
    def get_authorization_url(self)->str:
        """获取跳转授权认证的URL地址"""
        pass


    @abstractmethod
    def get_access_token(self, code:str)->str:
        """获取传入的code代码授权令牌"""
        pass


    @abstractmethod
    def get_raw_user_info(self, token:str)->dict:
        """根据传入的token获取OAuth原始信息"""
        pass


    @abstractmethod
    def _transform_user_info(self, raw_info:dict):
        """OAuth 的原始信息转换成OAuthUserInfo"""
        pass


    def get_user_info(self, token:str)->OAuthUserInfo:
        """根据传入的token 获取 OAuthUserInfo信息"""
        raw_info = self.get_raw_user_info(token)
        return self._transform_user_info(raw_info)

